<?php
namespace app\qianyu\model;
use think\Db;
use think\Model;

class Coupon extends Model
{
    protected $table = 'cbdd_coupon';

    //获取首页订单
    public function getParkCouponList($param){
        $list = $this->where('uid',$param)->alias('a')->join('cbdd_coupon_type b','a.type = b.id')->field('a.*,b.name bname,b.value bprice')->where('a.status',2)->order('expiration desc,bprice desc')->select();
        return $list;
    }
    //获取首页订单
    public function getParkCouponListCoulmn($param){
        $list = $this->where('uid',$param)->alias('a')->join('cbdd_coupon_type b','a.type = b.id')->where('a.status',2)->order('a.expiration desc,b.value asc')->column('b.value');
        return $list;
    }
    //获取首页订单
    public function getParkCouponListData($param){
        $list = $this->alias('a')->where('a.id','in',$param)->join('cbdd_coupon_type b','a.type = b.id')->field('sum(b.value) bprice')->where('a.status',2)->select();
        return $list;
    }
    public function SaveParkCouponStatus($param){
        $list = $this->where('id','in',$param)->save(['status'=>3,'updated_at'=>time()]);
        return $list;
    }
    //获取首页订单
    public function getParkCidData($param){
        $list = $this->alias('a')->where('a.id','in',$param)->join('cbdd_coupon_type b','a.type = b.id')->field('cid')->value('cid');
        return $list;
    }
}